package StudyCode.UI;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * @author lixiaoyao
 */
public class LookAndFeelFrame extends JFrame {

	private JPanel buttonPanel;

	public LookAndFeelFrame() {
		this.buttonPanel = new JPanel();
		UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
		for (UIManager.LookAndFeelInfo info : infos) {
			makeButton(info.getName(), info.getClassName());
		}
		add(this.buttonPanel);
		pack();
	}

	private void makeButton(String name, final String className) {
		// add button to panel

		JButton button = new JButton(name);
		this.buttonPanel.add(button);

		// set button action
		button.addActionListener(new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					UIManager.setLookAndFeel(className);
					SwingUtilities.updateComponentTreeUI(LookAndFeelFrame.this);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		});

	}

	public static void main(String[] args) {
		LookAndFeelFrame lookAndFeelFrame=new LookAndFeelFrame();
		lookAndFeelFrame.setSize(800,600);
		lookAndFeelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		lookAndFeelFrame.setVisible(true);
	}

}
